package com.adv.ems.manager.impl;

import com.adv.ems.db.mapper.CollectPointMapper;
import com.adv.ems.db.entity.CollectPointDO;
import com.adv.ems.enums.CollectPointDataTypeEnum;
import com.adv.ems.manager.CollectPointManager;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class CollectPointManagerImpl extends BaseManagerImpl<CollectPointMapper, CollectPointDO> implements CollectPointManager {
    @Override
    public void updateLastUploadInfo(Long pointId, Date lastUploadDate, Double realValue) {
        CollectPointDO record = new CollectPointDO();
        record.setId(pointId);
        record.setLastUploadRealValue(realValue);
        record.setLastUploadTime(lastUploadDate);
        updateById(record);
    }

    @Override
    public List<CollectPointDO> getPoints(Collection<Long> meterIds, CollectPointDataTypeEnum dataType) {
        return list()
                .stream()
                .filter(p -> meterIds.contains(p.getMeterId()))
                .filter(p -> dataType == null || dataType.name().equals(p.getDataType()))
                .collect(Collectors.toList());
    }
}
